#include "Font.h"
#include "Screen.h"
#include <assert.h>

Font::Font()
{
	static int howmany = 0;
	howmany++;
	if (1 == howmany)
	{
		TTF_Init(); // initialise True type fonts
	}

	m_font = 0;
}

Font::~Font()
{
	TTF_CloseFont(m_font);
}

bool Font::Load(const std::string& fontName, int pointSize)
{
	m_font = TTF_OpenFont(fontName.c_str(), pointSize);
	assert(m_font);
	return (m_font != 0);
}

void Font::Draw(const std::string& text, int x, int y)
{
	SDL_Color colour = {255, 255, 255, 255};
	SDL_Surface* image = TTF_RenderText_Blended(m_font, text.c_str(), colour);
	SDL_Rect r = {x, y, 0 , 0};
	SDL_BlitSurface(image, 0, Screen::Instance()->GetSurface(), &r);
	SDL_FreeSurface(image);
}